import java.util.Scanner;

public class HomeWork09{
    public static void main(String[] args) {
        new View().Mainmenue();
    }
}

class User {
    private String id;
    private String pwd;
    private String name;
    private String no;

    public User(String id, String pwd, String name, String no) {
        this.id = id;
        this.pwd = pwd;
        this.name = name;
        this.no = no;
    }

    public String getId() {
        return id;
    }

    public String getPwd() {
        return pwd;
    }

    public String getName() {
        return name;
    }

    public String getNo() {
        return no;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setNo(String no) {
        this.no = no;
    }
}

    class Functions{
        private int n;
        private int num=0;
        private User[] users;
        public Functions(int n){
            this.n=n;
            users=new User[n];
        }
        Scanner myScanner=new Scanner(System.in);
        public void regist(){
            if(num==n) {
                System.out.println("名额已满，无法注册");
                return ;
            }
            System.out.println("请输入你的用户名：");
            String name=myScanner.next();
            System.out.println("请输入你的手机号：");
            String no=myScanner.next();
            int s1=(int)(Math.random()*1000);
            int s2=(int)(Math.random()*10);
            char c1=(char)((int)Math.random()*26+'a');
            char c2=(char)((int)Math.random()*26+'a');
            char c3=(char)((int)Math.random()*26+'a');
            char c4=(char)((int)Math.random()*26+'a');
            String yzm="1"+s1+s2+c1+c2+c3+c4;


            System.out.println("验证码（请勿泄露）："+yzm);
            System.out.println("请输入验证码：");
            String yzm1=myScanner.next();
            int count=3;
            while(!yzm.equals(yzm1)&&count>0){
                System.out.println("验证码错误，请重新输入，剩余次数："+count--);
                yzm1=myScanner.next();
            }
            System.out.println("验证成功");


            System.out.println("请输入密码");
            String pwd=myScanner.next();
            System.out.println("请确认密码");
            String pwd1=myScanner.next();
            count=3;
            while(!pwd.equals(pwd1)&&count>0){
                System.out.println("密码不一致，请重新输入，剩余次数："+count--);
                pwd1=myScanner.next();
            }
            System.out.println("设置密码成功");


            s1=(int)(Math.random()*1000);
            s2=(int)(Math.random()*1000);
            String id="1"+s1+s2;
            System.out.println("你注册的id是："+id+"，请好好记住");
            System.out.println("注册已结束，程序退出。。。。");
            users[num++]=new User(id,pwd,name,no);
        }


        public void login(){
            System.out.println("请输入您的id");
            String id=myScanner.next();
            String pwd = null;
            int x=0;
            for(int i=0;i<num;i++){
                if(id.equals(users[i].getId())){
                    pwd= users[i].getPwd();
                    x=i;
                    break;
                }
            }
            System.out.println("请输入您的密码");
            String pwd1=myScanner.next();
            int count=3;

            while(!pwd.equals(pwd1)&&count>0){
                System.out.println("密码不正确，请重新输入，剩余次数："+count--);
                pwd1=myScanner.next();
            }
            System.out.println("登录成功");
            System.out.println("信息如下：");
            System.out.println("用户名：\t   id:\t手机号：\t密码：");
            System.out.println(users[x].getName() +"\t"+ users[x].getId() +"\t"+ users[x].getNo() +"\t"+ users[x].getPwd());

        }
    }


    class View{
        Functions func=new Functions(2);
        Scanner myScanner=new Scanner(System.in);
        public void Mainmenue(){
            boolean loop=true;

            String key="";
            do{
                System.out.println("\n欢====迎===来===到===xxxx");
                System.out.println("==========菜单如下：=========");
                System.out.println("=========1.  注册==========");
                System.out.println("===========2.登录============");
                System.out.println("=========3. 退出==============");
                System.out.println("请输入：");
                key=myScanner.next();
                switch(key){
                    case "1":
                        func.regist();
                        break;
                    case "2":
                        func.login();
                        break;
                    case "3":
                        loop=false;
                        break;
                    default :
                        System.out.println("输入有误，无效操做");
                        break;
                }


            }while(loop);

        }
    }
